import { defineConfig, loadEnv } from "vite";
import viteDevConfig from "./vite.dev.config";
import viteBaseConfig from "./vite.base.config";
import viteProdConfig from "./vite.prod.config";

const envResolver = {
  build: () => {
    console.log("生产环境.....");
    return {
      ...viteProdConfig,
      ...viteBaseConfig,
      plugins: viteBaseConfig.plugins.concat(viteProdConfig.plugins),
    };
  },
  serve: () => {
    console.log("开发模式.....");
    return {
      ...viteDevConfig,
      ...viteBaseConfig,
      plugins: viteBaseConfig.plugins.concat(viteDevConfig.plugins),
    };
  },
};

export default defineConfig(({ command, mode }) => {
  const env = loadEnv(mode, process.cwd(), "");
  console.log("env", env.ENV_PROXY_TARGET);
  return envResolver[command]();
});
